/**
 * 
 */
package com.hyxt.utils;

import java.io.UnsupportedEncodingException;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
 * @author songm
 * @version v1.0
 * @Description 读取propreties配置文件工具类
 * @Date: Create in 08:11 2017/12/21
 * @Modifide By:
 **/
public class PropretiesUtil {

	public static final String FileName = "params";

	private static ResourceBundle resources = null;

	public PropretiesUtil() {
	}

	public static String getPropertiesValueGBK(String propertiesName, String attr)
			throws UnsupportedEncodingException {
		String strItemValue = "";
		ResourceBundle resources1 = null;
		try {
			resources1 = ResourceBundle.getBundle(propertiesName);
			strItemValue = resources1.getString(attr);
			strItemValue = new String(strItemValue.getBytes("ISO8859-1"), "GBK");

		} catch (MissingResourceException e) {
			System.out.println("PropretiesUtil.getPropertiesValue error:"
					+ e.getMessage());
		}
		return strItemValue;
	}

	public static String getPropertiesValueUTF8(String propertiesName, String attr)
			throws UnsupportedEncodingException {
		String strItemValue = "";
		ResourceBundle resources1 = null;
		try {
			resources1 = ResourceBundle.getBundle(propertiesName);
			strItemValue = resources1.getString(attr);
			strItemValue = new String(strItemValue.getBytes("ISO8859-1"), "UTF-8");

		} catch (MissingResourceException e) {
			System.out.println("PropretiesUtil.getPropertiesValue error:"
					+ e.getMessage());
		}
		return strItemValue;
	}

	public static String getPropertiesValue(String strItem) {
		String strValue = "";
		try {
			if (resources == null)
				initResources();
			strValue = resources.getString(strItem);

		} catch (Exception e) {
			System.out.println("PropretiesUtil.getPropertiesValue error:"
					+ e.getMessage());
		}
		return strValue;
	}

	private static void initResources() {
		try {
			resources = ResourceBundle.getBundle(FileName);
		} catch (MissingResourceException e) {
			throw new Error(e.getClassName());
		}
	}
}
